package com.leaf.lowcode.utils.jsontobean;

import com.alibaba.fastjson.JSONObject;
import com.leaf.lowcode.entity.Origin;

import java.lang.reflect.Field;

public class OriginToTransfer<T> implements ToTranfer<T> {
    @Override
    public T laod(Field field, Object o, T cls) {
        JSONObject jsonObject= JSONObject.parseObject(o.toString());
        double x = Double.parseDouble(jsonObject.get("x").toString());
        double y = Double.parseDouble(jsonObject.get("y").toString());
        double theta = Double.parseDouble(jsonObject.get("theta").toString());
        Origin origin = new Origin(x, y, theta);
        try {
            field.setAccessible(true);
            field.set(cls,origin);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return cls;
    }
}
